package com.jz.main.io.lock;

import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 字符串反转
//        String str = "abcdefh";
//        StringBuilder builder = new StringBuilder();
//        for (int i = 0; i < str.length(); i++) {
//            builder.append(str.charAt(str.length()-i-1));
//        }
//        System.out.println(builder.toString());
        //
        ThreadPoolExecutor pool = new ThreadPoolExecutor(2,2,1000, TimeUnit.HOURS,new ArrayBlockingQueue<Runnable>(1));
        Callable<String> t1 = new Callable<String>() {

            @Override
            public String call() throws Exception {
                System.out.println(1);
                return "1";
            }
        };
        Callable<String> t2 = new Callable<String>() {

            @Override
            public String call() throws Exception {
                System.out.println(2);
                return "2";
            }
        };
        Future<String> task1 = pool.submit(t1);
        Future<String> task2 = pool.submit(t2);

        System.out.println(task1.get());
        System.out.println(task2.get());
        pool.shutdown();

    }


    static void test() throws InterruptedException{
        //        ReentrantLock reentrantLock;
        CountDownLatch a = new CountDownLatch(1);
//        a.countDown();
        a.await();
    }

}
